Ext.onReady(function(){
	REGION_DISK.initPage();
});
var REGION_DISK={
		initPage: function(){
			Ext.create('Ext.container.Viewport', {
			    layout: 'border',
			    frame:false,
			    border:false,
			    items: [{
			    	region: 'west',
			        split: true,
			        width: 220,
			        layout: 'fit',
			        items:[REGION_DISK.initTree()]
			    },{
			    	id: 'mainPanel',
			        region: 'center',
			        layout: 'fit',
			        items:[REGION_DISK.regionGrid()]
			    }]
			});
		},
		initTree: function(){
			//树
		 	var tree = Ext.create("Ext.com.bkfm.tree",{
		 		id: "regionTree",
		 		rootVisible: true,
		 		rootLabel: "中国",
		 		treeConfigId: "region",
		 		rootTreeId: "000000",
		 		objPath: 'ROOT/XTGLPT/SJZDGL/BLK_DIC_REGION',
		 		border: false,
		 		autoScroll: true,
		 		tbar:[{
		 			text: '新增',
		 			iconCls: 'add',
		 			handler: function(){
		 				REGION_DISK.editTree();
		 			}
		 		},{
		 			text: '修改',
		 			iconCls: 'edit',
		 			handler: function(){
		 				var menuTree = Ext.getCmp("regionTree");
		 				REGION_DISK.editTree(menuTree.getSelectNode());
		 			}
		 		},{
		 			text: '删除',
		 			iconCls: 'delete',
		 			handler: function(){
		 				//var menuTree = Ext.getCmp("menuTree");
	 					//menuTree.delSelectNode(menuTree.getSelectNode());
		 			}
		 		}],
		 		viewConfig:{
		            plugins :{
		                ptype:'treeviewdragdrop',
		                //appendOnly:true         //只能拖着带非叶节点上
		            },
		            listeners:{//监听器
		                drop:function(node,data,overModel,dropPosition,options){
		                    return false;
		                },
		                beforedrop:function(node,data,overModel,dropPosition,dropFunction,options){
		                	return false;
		                }
		            }
		        }
		 	});
		 	tree.on("itemclick",function(view,record,item,index,e,opts){
		 		var region_no = record.get("id");
		 		//var title = record.get("text");
		 		//var isleaf = record.get("leaf");
		 		//var menuRoleGrid = Ext.getCmp("menuRoleGrid");
		 		//menuRoleGrid.search(" MENU_RWID='"+id+"'");
		 		var regionGrid = Ext.getCmp("region_grid");
		 		regionGrid.search(" FATHER_REGION_NO='"+region_no+"'");

		 	})
		 	return tree;
		},
		editTree: function(record){
			var menuTree = Ext.getCmp("regionTree");
			var form = Ext.create('Ext.com.bkfm.form', {
				showGroup : false,
				columnCount: 2,
				border : false,
				frameborder : false,
				objPath : "ROOT/XTGLPT/SJZDGL/BLK_DIC_REGION"
			});
			var win = Ext.create('Ext.com.bkfm.window', {
				title : '编辑菜单',
				autoScroll : true,
				modal : true,
				height : Utils.getHeight()*0.5,
				width : Utils.getWidth()*0.5,
				items: [form],
				tbar : [ {
					text : '保存',
					iconCls : 'save',
					handler : function() {
						form.save(function(){
							win.close();
							menuTree.reloadSelectNode();
						});

					}
				} ]
			});
			win.show(this,function(){
				if(record){
					form.loadRemoteData(null,null," region_no='"+record.get("id")+"'");
				}
			});
		},
		regionGrid: function(){
			var region_grid = Ext.create('Ext.com.bkfm.datagrid', {
				id: "region_grid",
				objPath : "ROOT/XTGLPT/SJZDGL/BLK_DIC_REGION",
				height: Utils.getHeight(),
				border: true,
				orderby : ' ORDER BY ORDER_BY ASC',
				customBtn:[{
					text: '导出',
					iconCls: 'export',
					handler: function(){
						usergrid.exportGridDate();
					}
				},{
					text: '导入',
					iconCls: 'import',
					handler: function(){
						region_grid.importGridData();
					}
				}],
				afterFormShow: function(grid,formTabPanel){
					
				},
				beforeFormSave: function(grid,formTabPanel,win){
					
				}
			});
			return region_grid;
		}
}